import axios from '@/libs/axios1'
let jsonHeaders = { 'content-type': 'application/json;charset=UTF-8' }
let base = '/testplatform/productComponent'

// 查询组件
export const queryProductComponentList = params => {
  return axios({
    url: `${base}/page`,
    method: 'GET',
    params,
    headers: jsonHeaders,
  })
}

// 创建组件
export const addProductComponent = data => {
  return axios({
    url: `${base}/add`,
    method: 'POST',
    data,
    headers: jsonHeaders,
  })
}

// 修改组件
export const updateProductComponent = data => {
  return axios({
    url: `${base}/update`,
    method: 'PUT',
    data,
    headers: jsonHeaders,
  })
}

// 删除组件
export const deleteProductComponent = data => {
  return axios({
    url: `${base}/delete`,
    method: 'DELETE',
    data,
    headers: jsonHeaders,
  })
}

// 为组件创建依赖
export const addRelationComponent = (id, productId, data) => {
  return axios({
    url: `${base}/${id}/saveRelationBatch`,
    method: 'POST',
    params: {
      productId
    },
    data,
    headers: jsonHeaders,
  })
}

// 为组件删除依赖
export const deleteRelationComponent = (id, productId, data) => {
  return axios({
    url: `${base}/${id}/deleteRelationBatch`,
    method: 'DELETE',
    data,
    headers: jsonHeaders,
  })
}

// 查询组件的依赖
export const getRelationComponent = id => {
  return axios({
    url: `${base}/getComponentDependenceRelationById/${id}`,
    method: 'POST',
    headers: jsonHeaders,
  })
}

// 查询组件关联的其他组件，包含上下级
export const getRelationModule = id => {
  return axios({
    url: `${base}/queryComponentDependencyRelationByComponentId/${id}`,
    method: 'POST',
    headers: jsonHeaders,
  })
}

// 查询组件关联的其他部件，包含上下级
export const getRelationPart = id => {
  return axios({
    url: `${base}/queryPartRelationByComponentId/${id}`,
    method: 'POST',
    headers: jsonHeaders,
  })
}

// 查询组件关联的其他产品，包含上下级
export const getRelationProduct = id => {
  return axios({
    url: `${base}/queryProductRelationByComponentId/${id}`,
    method: 'POST',
    headers: jsonHeaders,
  })
}

// 获取组件漏洞统计数据
export const componentMetrics = id => {
  return axios({
    url: `${base}/metrics/${id}`,
    method: 'GET',
    headers: jsonHeaders,
  })
}

// 为部件关联组件
export const addModuleToPartBatch = (partId, data) => {
  return axios({
    url: `${base}/updUpgradeComponentV2/${partId}`,
    method: 'PUT',
    data,
    headers: jsonHeaders,
  })
}